package org.example.domain;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.List;

/**
 * 覆盖pageinfo的信息，提取出有用的信息
 * @Author hxy
 * @Date 2021/3/15 22:44
 * @Version 1.0
 */
public class PageInfoDTO<T> extends PageVO implements Serializable {
    @ApiModelProperty("总记录数")
    private long total;

    @ApiModelProperty("总页数")
    private int pages;

    @ApiModelProperty("记录数据")
    private List<T> list;

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public static <T> PageInfoDTO<T> to(PageInfo<T> pageInfo) {
        PageInfoDTO<T> page = new PageInfoDTO<>();
        page.setList(pageInfo.getList());
        page.setPageSize(pageInfo.getPageSize());
        page.setPageNum(pageInfo.getPageNum());

        page.setTotal(pageInfo.getTotal());
        page.setPages(pageInfo.getPages());

        return page;
    }
}
